<?php

namespace App\Http\Controller;

use App\Foundation\Utils\GuzzleWrap;
use App\Http\Event\Member\Listener\ListenerA;
use App\Http\Event\Member\Listener\ListenerB;
use App\Http\Event\Member\MemberRegister;
use Filterus\Filter;
use Framework\Foundation\Event\Event;
use Framework\Foundation\Event\EventDispatcher;
use Framework\Foundation\Event\EventLauncher;
use Framework\Foundation\Event\ListenerProvider;
use Framework\Foundation\Event\StoppableEvent;
use Framework\Foundation\Log\Log;
use Framework\Foundation\Log\LoggerHelper;
use Framework\Foundation\Log\ZipLog;
use Framework\Foundation\Queue\Interfaces\QueueHandler;
use Framework\Foundation\Queue\RedisQueue;
use Framework\Foundation\Warehouse;
use Framework\Foundation\Zipkin\ZipkinAssistant;
use Framework\Utils\RedisFactory;
use iamcal\SQLParser;
use Framework\Foundation\Database\SchemaValidator;
use Framework\Foundation\Zipkin\ZipkinHelper;
use function PHPSTORM_META\type;

class Index
{
    public function index()
    {
        Log::info("test");
        echo '<pre>';
        print_r('framework');
        exit('</pre>');
//        $filter = Filter::map(array(
//            'foo' => 'int',
//            'bar' => 'regex,regex:/\d{4}/',
//        ));
//
//        $data = [
//            'foo' => 4,
//            'bar' => '123a5342'
//        ];
//
//        $ret = $filter->validate($data);
//        echo '<pre>';
//        var_dump($ret);
//        exit('</pre>');

//        $parser = new SQLParser();
        $sql = '
CREATE TABLE `test` (
  `test_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `hah` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `he` int(255) DEFAULT NULL,
  `status` tinyint(4) DEFAULT \'1\',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`test_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;      
        ';

        $schemeValidator = new SchemaValidator();
        $ret = $schemeValidator->getValidatorBySql($sql);
        echo '<pre>';
        print_r($ret);
        exit('</pre>');

        echo '<pre>';
        print_r($parser->parse($sql));
//        print_r( $parser->tables );
        exit('</pre>');

        $config = Config::getInstance()->get('database.mysql.default');
        $pdo = new \PDO($config['host'], $config['username'], $config['password']);

        $statment = $pdo->query("show tables");


        $ret = DB::from('member')->fetchAll();


//        $ret = DB::connection('default')->from('member')->fetchAll();

        echo '<pre>';
        print_r($ret);
        exit('</pre>');
        echo '<pre>';
        print_r($config);
        exit('</pre>');
        echo '<pre>';
        print_r('index controller action');
        exit('</pre>');
    }
}
